package org.sy.lab.多线程基础._3_同步辅助类._2_CountDownLatch门阀;

import java.util.concurrent.TimeUnit;

//CountDownLatch可以提供类似join的功能
//await等待其他线程，在计数减为0的时候继续执行
//例子里10个人参与众筹，在6个人参加后众筹成功
public class Main {

	public static void main(String[] args) {
		
		Crowdfunding crowdfunding = new Crowdfunding(6);
		Thread thread = new Thread(crowdfunding);
		thread.start();
		
		MyThread myThread = new MyThread(crowdfunding);
		for (int i = 1; i <= 10; i++) {
			Thread thread2 = new Thread(myThread, "客户" + i);
			thread2.start();
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
